export 'img_util.dart';
export '../route/routes.dart';
export 'icon_util.dart';
export 'keys.dart';
export 'storage.dart';

export 'httputils/net_api.dart';
export 'httputils/result_data.dart';
export 'upload.dart';
export 'color.dart';
export 'file.dart';

export 'package:top_foundation/top_foundation.dart';

bool isZeroList(List? a) {
  if (a == null) {
    return true;
  }

  if (a.isEmpty) {
    return true;
  }
  return false;
}

bool isNilStr(String? str) {
  if (str == null) {
    return true;
  }
  if (str == '') {
    return true;
  }

  if (str == 'null') {
    return true;
  }

  return false;
}

bool isZero(dynamic x) {
  if (x == null) {
    return true;
  }
  if (x is String) {
    int _x = int.tryParse(x) ?? 0;
    if (_x == 0) {
      return true;
    }
    return false;
  }
  if (x is int) {
    return x == 0;
  }
  return true;
}

num numVal(dynamic x) {
  if (x == null) {
    return 0;
  }
  if (x is String) {
    return num.tryParse(x) ?? 0;
  }
  if (x is num) {
    return x;
  }
  return 0;
}

String getDurationStr(dynamic duration) {
  if (duration == null) {
    return '0';
  }
  int _duration = 0;
  if (duration is String) {
    _duration = int.tryParse(duration) ?? 0;
  }
  if (duration is int) {
    _duration = duration.toInt();
  }

  if (_duration <= 0) {
    return '0';
  }

  var minutes = (_duration / 60).truncate();
  var second = _duration - minutes * 60;

  if (minutes <= 0) {
    return '${second}s';
  }
  if (minutes > 0 && minutes < 60) {
    return '$minutes:$second';
  }
  if (minutes > 90) {
    var hour = (minutes / 60).truncate();
    var _minute = minutes - hour * 60;
    return '$hour:$_minute:$second';
  }
  return '0';
}
